package com.sl.au.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.PartsWarn;

public interface PartsWarnRepository extends JpaRepository<PartsWarn, String> {
	/**
	  * 从PartsWarn表获取分组的下拉框选项
	  * @param group
	  * @return
	  */
//	 @Query("select o from PartsWarn o where o.group = ?1 and o.title !='大型活动' and o.title !='大型活动安全防范' order by o.createTime asc")
//	 List<PartsWarn> findByGroup(String group);
	 /**
	  * 从PartsWarn表获取分组的下拉框选项
	  * @param group
	  * @return 返回String 集合
	  */
//	 @Query("select o.title from PartsWarn o where o.group = ?1 order by o.createTime asc")
//	 List<String> findPartsWarnByGroup(String group)
	 
	 /**
	  * 从PartsWarn表通过获取分组和标题获取下拉框选项
	  * @param group
	  * @return
	  */
//	 @Query("select o from PartsWarn o where o.group = ?1 and o.title = ?2 order by o.createTime asc")
//	 List<PartsWarn> findByGroupAndTitle(String group, String title);
	 

	 /**
	 * @param key
	 * @param pageable
	 * @return 得到选项配置PartsWarn的page，关键字为key
	 */
	@Query("SELECT a FROM PartsWarn a where a.partsAttributes.partsType.id like %?1% "
			+ "and (a.partsAttributes.attributes like %?2% "
			+ "or a.partsAttributes.attributes_name like %?2%) "
			+ "order by a.partsAttributes.partsType.parts_name,a.partsAttributes.attributes")
//			+ "where a.attributes_name like %?1% or a.partsType like %?1% or a.attributes like %?1% order by a.partsType,a.attributes")
	 Page<PartsWarn> findPartsWarn(String id , String key, Pageable pageable);
	 /**
	 * @param key
	 * @return 得到选项配置PartsWarn的条数，关键字为key
	 */
	@Query(" select count(*) as num from PartsWarn a where a.partsAttributes.partsType.id like %?1% " 
			+ "and (a.partsAttributes.attributes like %?2% " 
			+ "or a.partsAttributes.attributes_name like %?2%) ")
//			+ "where a.attributes_name like %?1% or a.partsType like %?1% or a.attributes like %?1% ")
	 Long getPartsWarnCount(String id , String key);
	/**
	 *通过Attributesid得到所有的参数
	 */
	@Query(" select o from PartsWarn o where o.partsAttributes.id = ?1 ")
	List<PartsWarn> findAllWarnById(String attributesId);
}
